<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增学员信息')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-student-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label">姓名：</label>
                <div class="col-sm-8">
                    <input name="name" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">账号：</label>
                <div class="col-sm-8">
                    <input name="account" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">密码：</label>
                <div class="col-sm-8">
                    <input name="password" class="form-control" type="password">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">邮件：</label>
                <div class="col-sm-8">
                   <input name="email" class="form-control" type="email">                    
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">电话：</label>
                <div class="col-sm-8">
                    <input name="phone" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">QQ号：</label>
                <div class="col-sm-8">
                    <input name="qq" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">微信号：</label>
                <div class="col-sm-8">
                    <input name="wechat" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">性别：</label>
                <div class="col-sm-8">
                    <select name="sex" class="form-control m-b" th:with="type=${@dict.getType('sys_user_sex')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">                
                <label class="col-sm-3 control-label" for="coursePicture">头像：</label>
                <input name="img" id="img" class="form-control" type="hidden">
                <div class="col-sm-8">                    
                    <input type="file" class="" name="coursePicture" id="coursePicture" accept="image/*"/>
                    <img src="" alt="" id="yl" width="20px" height="20px" display="none"/>
                    <button class="btn" type="button" id="upload">上传</button>
                </div>
            </div>             
            <div class="form-group">    
                <label class="col-sm-3 control-label">生日：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="birthday" class="form-control" placeholder="yyyy-MM-dd" type="text">
                    </div>
                </div>                
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">身份证号：</label>
                <div class="col-sm-8">
                    <input name="idcard" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">地址：</label>
                <div class="col-sm-8">
                    <textarea name="address" class="form-control"></textarea>
                </div>
            </div>
            <!-- <div class="form-group">    
                <label class="col-sm-3 control-label">积分：</label>
                <div class="col-sm-8">
                    <input name="score" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">账户余额：</label>
                <div class="col-sm-8">
                    <input name="money" class="form-control" type="text">
                </div>
            </div> 
            <div class="form-group">    
                <label class="col-sm-3 control-label">班级编号：</label>
                <div class="col-sm-8">
                    <input name="classId" class="form-control" type="text">
                </div>
            </div>
            -->
            <div class="form-group">    
                <label class="col-sm-3 control-label">班级名称：</label>
                <input name="className" id="className" class="form-control" type="hidden">
                <div class="col-sm-8">
                 <select class="form-control m-b" name="classId" id="classId">                  
                   <option th:each="class : ${classes}" th:text="${class.name}" th:value="${class.id}"></option>
                </select>   
                    
                </div>
            </div>
           <!--  <div class="form-group">    
                <label class="col-sm-3 control-label">状态(1正常,2冻结,3.失效,0删除)：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('wct_student_status')}">
                        <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}" th:checked="${dict.default}">
                        <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div> 
            <div class="form-group">    
                <label class="col-sm-3 control-label">注册时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="registerTime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                    </div>
                </div>
            </div>
            -->
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script type="text/javascript">
        var prefix = ctx + "course/student"
        $("#form-student-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
            	//把教师的名称也提交到后台
            	$("#className").val($("#classId").find("option:selected").text());
                $.operate.save(prefix + "/add", $('#form-student-add').serialize());
            }
        }

        $("input[name='birthday']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
        
        //图片......
        $('#coursePicture').on('change', function() {
            var reader = new FileReader();
            reader.onload = function(e) {
                var src = e.target.result;
                //根据MIME判断上传的文件是不是图片类型
                if((src).indexOf("image/")==-1){
                    $.modal.alertWarning("文件格式错误，请上传图片类型,如：JPG，PNG后缀的文件。");                    
                } else {
                    $("#yl").attr("src",src);
                }
            }
            reader.readAsDataURL(this.files[0]);
        })
        
       //确定图片上传的话......
       $("#upload").click(function(){
    	   //判断文件是否为空
    	   var file=$("#coursePicture")[0];
    	   if(file.value==null || file.value==''){
    		   $.modal.alertWarning("请先选择上传的图片,图片类型,如：JPG，PNG后缀的文件。");   
    		   return;    		   
    	   }    	   
    	   var formdata = new FormData();
    	   formdata.append("coursePicture",file.files[0]);
    	   $.ajax({
    	        url: prefix + "/uploadImg",
    	        data: formdata,
    	        type: "post",
    	        processData: false,
    	        contentType: false,
    	        success: function(result) {    	        	
    	        	if(result.code=='0'){    
    	        		$.modal.alertWarning("上传图片成功......");
    	        		$("#img").val(result.msg);    	        		
    	        	}else{    	        		
    	        		$.modal.alertWarning("上传图片失败！请重新上传图片,图片类型如：JPG，PNG后缀的文件。");
    	        	}    	        	
    	        }
    	    })   	   
       });       
        
        
        
        
    </script>
</body>
</html>